package com.Algorithm.leetcode.Demo01;
/*
*
* 示例 1：
*
*输入：nums = [2,7,11,15], target = 9
*输出：[0,1]
*解释：因为 nums[0] + nums[1] == 9 ，返回 [0, 1] 。
*
*示例 2：
*输入：nums = [3,2,4], target = 6
输出：[1,2]
*
*
* 示例 3：
输入：nums = [3,3], target = 6
输出：[0,1]
*
* */
public class TwoSumTest {
    public int[] twoSum(int[] nums, int target) {
        int order[] = new int[2];

        int a=0;
        int b=0;
        for(int index1=0;index1<nums.length;index1++){
            for (int index2=0;index2<nums.length;index2++){
                if((nums[index1] + nums[index2]) == target && index1!=index2){
                    a = index1;
                    b = index2;
                }
            }
        }

        if(a>b){
            int m = a;
            a=b;
            b=m;
        }
        order[0] = a;
        order[1] = b;

        return order;
    }


    public static void main(String[] args) {
        int[] nums = new int[]{3,2,3,2,5,4,4};
        int target = 6;
        TwoSumTest twoSumTest = new TwoSumTest();
        int[] ints = twoSumTest.twoSum(nums, target);

        for (int anInt : ints) {
            System.out.print(anInt+" ");
        }


    }
}
